﻿using Sidvall.Serialization;
using System;
using System.Globalization;

namespace Sidvall.UI.Wpf.Converters
{
    public class DecimalToStringConverter : ValueToStringConverterBase
    {
        #region Public Members

        #region StringToValue

        protected override object StringToValue(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value.ToNullableDecimal(NumberStyles.Any, culture);
        }

        #endregion
        #region ValueToString

        protected override string ValueToString(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is decimal))
                return null;
            return ((decimal)value).ToString(culture);
        }

        #endregion

        #endregion
    }
}
